package com.ldkj.msg.user.controller;

import com.ldkj.msg.common.ResultMap;
import com.ldkj.msg.user.service.MsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;

@Controller
@RequestMapping("rtsp")
public class MsgController {
    @Autowired
    private MsgService userService;

    ResultMap resultMap = new ResultMap();

    @Autowired
    RestTemplateBuilder builder;

    @ResponseBody
    @PostMapping("uploadUD")
    public ResultMap uploadUD(String message,HttpServletRequest request){

        Enumeration<String> parameterNames = request.getParameterNames();
        while (parameterNames.hasMoreElements()) {
            String parameterName = parameterNames.nextElement();
            System.out.println(parameterName + "===" + request.getParameter(parameterName));
        }

        System.out.println("message==="+message);
        resultMap.message(message);
        return resultMap;
    }

    @ResponseBody
    @PostMapping("getWxMsg")
    public ResultMap getWxMsg(HttpServletResponse response,String icon, String username, String time,String msg){
        resultMap.message("icon="+icon);
        resultMap.message("username="+username);
        resultMap.message("time="+time);
        resultMap.message("msg="+msg);
        return resultMap;
    }

    @ResponseBody
    @GetMapping("getMsgByRoom")
    public ResultMap getMsgByRoom(String room){
        resultMap.message(userService.getMsgByRoom(room));
        return resultMap;
    }


    @ResponseBody
    @PostMapping("rcontact")
    public ResultMap rcontact(String username,
                              String nickname){
        userService.addRcontact(username,nickname);
        return resultMap;
    }

    @ResponseBody
    @PostMapping("message")
    public ResultMap message(String msgid,
                              String createtime,
                              String talker,
                              String content,
                              String username){
        userService.addMessage(msgid,
                createtime,
                talker,
                content,
                username);
        return resultMap;
    }


}